package com.jack.leetcode._2021;

public class findMaxConsecutiveOnes {

    public int findMaxConsecutiveOnes(int[] nums) {
        int n = nums.length;
        int result = 0;
        for(int i = 0;i < n;i++){
            if(nums[i] == 1){
                int tmp = 1;
                while(i < n - 1 && nums[i + 1] == 1){
                    i++;
                    tmp++;
                }
                result = Math.max(result, tmp);
            }
        }
        return result;
    }

    public static void main(String[] args) {
//        System.out.println(new findMaxConsecutiveOnes().findMaxConsecutiveOnes(new int[]{1,1,0,1,1,1}));
        new findMaxConsecutiveOnes().matrixReshape(new int[][]{{1,2,3,4}},2,2);
    }

    public int[][] matrixReshape(int[][] nums, int r, int c) {
        int m = nums.length, n = nums[0].length;
        int count = m * n;
        if(r * c != count ){
            return  nums;
        }
        int[][] result = new int[r][c];
        int index = 0;
        for(int i = 0;i < r;i++){
            for(int j = 0;j < c;j++){
                result[i][j] = nums[index / n][index % n];
                index++;
            }
        }
        return result;
    }
}
